package com.pansoft.openplanet.fragment;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.core.xml.StubObject;
import com.efounder.frame.baseui.BaseFragment;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.Account;

public class EmptyBlockChainListFragment extends BaseFragment implements View.OnClickListener{

    private LinearLayout llEmptyLayout;
    private Button tvCreateWallet;
    private Button tvRestoreWallet;
    private ImageView ivIcon;
    private TextView tvTextTitle;
    private ProgressBar progressBar;
    private Account currentAccout;

    private String blockChainName;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.open_planet_fragment_wallet_list, container, false);
        initView(rootView);
        initData();
        return rootView;
    }

    private void initView(View rootView) {
        llEmptyLayout = (LinearLayout) rootView.findViewById(R.id.ll_empty_layout);
        tvCreateWallet = (Button) rootView.findViewById(R.id.tv_create_wallet);
        tvRestoreWallet = (Button) rootView.findViewById(R.id.tv_restore_wallet);
        llEmptyLayout.setVisibility(View.VISIBLE);
        ivIcon = (ImageView) rootView.findViewById(R.id.iv_icon);
        tvTextTitle = (TextView) rootView.findViewById(R.id.tv_text_title);
        tvRestoreWallet.setOnClickListener(this);
        tvCreateWallet.setOnClickListener(this);
    }

    private void initData() {
        if (getArguments() != null && getArguments().containsKey("stubObject")) {
            StubObject stubObject = (StubObject) getArguments().getSerializable("stubObject");
            if (stubObject != null) {
                if (stubObject.getString("id", "").equals("etc")) {
                    blockChainName = "ETC";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_etc));
                } else if (stubObject.getString("id", "").equals("bch")) {
                    blockChainName = "BCH";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_bch));
                } else if (stubObject.getString("id", "").equals("btm")) {
                    blockChainName = "BTM";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_btm));
                } else if (stubObject.getString("id", "").equals("ltc")) {
                    blockChainName = "LTC";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_ltc));
                } else if (stubObject.getString("id", "").equals("xrp")) {
                    blockChainName = "XRP";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_xrp));
                } else if (stubObject.getString("id", "").equals("gxm")) {
                    blockChainName = "GXM";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_gxs));
                } else if (stubObject.getString("id", "").equals("qtum")) {
                    blockChainName = "QTUM";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_qtum));
                } else if (stubObject.getString("id", "").equals("act")) {
                    blockChainName = "ACT";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_act));
                } else {
                    blockChainName = "BTC";
                    ivIcon.setImageDrawable(getResources().getDrawable(R.drawable.ipasset_wallet_list_btc));
                }
            }
        }

        tvTextTitle.setText(blockChainName);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_restore_wallet) {
            new AlertDialog.Builder(getActivity()).setTitle(blockChainName)
                    .setMessage(ResStringUtil.getString(R.string.open_planet_recharge_no_dredge))
                    .setCancelable(true)
                    .setPositiveButton(ResStringUtil.getString(R.string.common_text_confirm), null).show();
        } else if (id == R.id.tv_create_wallet) {
            new AlertDialog.Builder(getActivity()).setTitle(blockChainName)
                    .setMessage(ResStringUtil.getString(R.string.open_planet_recharge_no_dredge))
                    .setCancelable(true)
                    .setPositiveButton(ResStringUtil.getString(R.string.common_text_confirm), null).show();
        }
    }
}
